package Demo25;

import java.util.Scanner;

/**
 * [模版]前缀和
 * https://www.nowcoder.com/practice/acead2f4c28c401889915da98ecdc6bf?tpId=230&tqId=2021480&ru=/exam/oj&qru=/ta/dynamic-programming/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196
 * 这里的思想重要是创建一个dp数组,计算前缀和
 *  只需要使用  right - left - 1 即可求出我们需要的区间
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    /**
     * 优化后
     * @param args
     */
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        int[] arr = new int[n + 1];
        long[] dp = new long[n+1];
        arr[0] = 0;
        dp[0] = 0;
        for(int i = 1; i < n + 1;i++) {
            arr[i] = scanner.nextInt();
            dp[i] = dp[i - 1] + arr[i];
        }
        for(int i = 1; i <= q;i++) {
            int left = scanner.nextInt();
            int right = scanner.nextInt();
            System.out.println(dp[right] - dp[left - 1]);
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        int[] arr = new int[n + 1];
        // 1. 读入数据
        for(int i = 1; i < n + 1;i++) {
            arr[i] = scanner.nextInt();
        }
        arr[0] = 0;
        long[] dp = new long[n+1];
        dp[0] = 0;
        //2. 预处理一个前缀和数组
        for(int i = 1; i < n + 1;i++) {
            dp[i] = dp[i - 1] + arr[i];
        }
        //3. 使用前缀和数组
        for(int i = 1; i <= q;i++) {
            int left = scanner.nextInt();
            int right = scanner.nextInt();
            System.out.println(dp[right] - dp[left - 1]);
        }
    }
}